package cn.math.appmath.action;

import org.apache.struts2.ServletActionContext;

import cn.math.appmath.bean.ActivityBean;
import cn.math.appmath.biz.ActivityBiz;
import cn.math.appmath.entity.Activity;

import com.opensymphony.xwork2.ActionSupport;

public class ActivityAction extends ActionSupport {
	private static final long serialVersionUID = -4565898601842133546L;
	private ActivityBiz activityBiz;
	private ActivityBean activityBean;
	private Activity activity;
	private String message;
	private String btime;
	private String ftime;
	private Integer[] nos;
	
	public String findActivity(){
		int page = Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));
		String param = ServletActionContext.getRequest().getParameter("param");
		activityBean = activityBiz.findAll(page, param);
		return SUCCESS;
	}
	
	/**
	 * 后台查看学术交流列表
	 * @return
	 */
	public String backFindActivity(){
		int page = 0;
		String pageStr = ServletActionContext.getRequest().getParameter("page");
		String param = ServletActionContext.getRequest().getParameter("param");
		if(pageStr != null && !pageStr.equals(""))
			page = Integer.parseInt(pageStr);
		if(param == null || param.equals(""))
			param = "backward";
		activityBean = activityBiz.findAll(page, param);
		return SUCCESS;
	}

	public String activityforward(){
		message = "";
		return SUCCESS;
	}
	
	/**
	 * 添加学术交流信息
	 * @return
	 */
	public String addActivity(){
		String atime = btime + "——" + ftime;
		activity.setAtime(atime);
		if(activityBiz.save(activity)){
			message = "添加学术交流信息成功";
			return SUCCESS;
		}
		message = "添加学术交流信息失败";
		return INPUT;
	}
	
	/**
	 * 删除单条记录
	 * @return
	 */
	public String delActivity(){
		Integer ano = new Integer(ServletActionContext.getRequest().getParameter("ano"));
		if(activityBiz.delete(ano)){
			return SUCCESS;
		}else{
			message = "删除学术交流信息失败";
			return INPUT;
		}
	}
	
	/**
	 * 批量删除记录
	 * @return
	 */
	public String batchDeleteActivity(){
		if(activityBiz.batchDelete(nos)){
			return SUCCESS;
		}else{
			message = "删除学术交流信息失败";
			return INPUT;
		}
	}
	
	public ActivityBean getActivityBean() {
		return activityBean;
	}

	public void setActivityBean(ActivityBean activityBean) {
		this.activityBean = activityBean;
	}

	public void setActivityBiz(ActivityBiz activityBiz) {
		this.activityBiz = activityBiz;
	}

	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getBtime() {
		return btime;
	}

	public void setBtime(String btime) {
		this.btime = btime;
	}

	public String getFtime() {
		return ftime;
	}

	public void setFtime(String ftime) {
		this.ftime = ftime;
	}

	public Integer[] getNos() {
		return nos;
	}

	public void setNos(Integer[] nos) {
		this.nos = nos;
	}
}
